<template>
  <div class="page-root">
    <BasePanel>
      <BasePanel>
        <BaseSearch :search="searchProps" @searchData="updateTable" @resetData="updateTable" />
        <div class="table-top-wrap">
          <div class="table-title">
            <span>列表</span>
          </div>
        </div>
        <BaseTable :loading="loading" :columns="columns" :dataSource="dataSource" :pagination="false"
          :scroll="{ x: 1000 }"></BaseTable>
        <div v-show="dataSource.length > 0" class="page-footer">
          <BasePagination :page-key.sync="pageKey" :get-list="tableInit" />
        </div>
      </BasePanel>
    </BasePanel>
  </div>
</template>

<script>
import { searchProps, columns } from './option.js';
import * as Ajax from '@/api/channel';
export default {
  data() {
    return {
      searchProps,
      columns,
      searchForm: {},
      loading: true,
      dataSource: [],
      pageKey: {
        pageSize: 10,
        total: 1,
        current: 1,
      },
    };
  },
  created() {
    this.tableInit();
  },
  methods: {
    updateTable(params = {}) {
      this.searchForm = { ...params };
      this.pageKey = this.$options.data().pageKey;
      this.tableInit();
    },
    // table 初始化
    tableInit() {
      this.loading = true;
      const { current, pageSize } = this.pageKey;
      const params = { pageNum: current, pageSize, ...this.searchForm };
      Ajax.getUserList(params)
        .then((res) => {
          const { data, totalCount } = res;
          this.dataSource = Array.isArray(data) ? data : [];
          this.pageKey.total = totalCount;
        })
        .finally(() => {
          this.loading = false;
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.BasePanel-root {
  padding: 10px 20px 20px;
}

.tabs-wrap {
  margin-bottom: 10px;
}

.table-wrap {
  margin-top: 16px;
}

.table-top-wrap {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.table-title {
  flex: 1;

  span {
    line-height: 32px;
    font-weight: bold;
    font-size: 16px;
    display: flex;
    align-items: center;

    &::before {
      content: '';
      display: block;
      width: 3px;
      height: 18px;
      background-color: #1890ff;
      margin-right: 8px;
      position: relative;
      top: -1px;
    }
  }
}

.btn-gruop {
  display: flex;
  justify-content: flex-end;

  &>button {
    margin-left: 12px;

    &:first-child {
      margin-left: 0;
    }
  }
}
</style>
